<template>
    <div>
        <router-link to="/">
            <div class="header-abs">
                <div class="header-left">
                    <span class="iconfont iconfanhui return_icon"></span>
                </div>
            </div>
        </router-link>
        <div class="header-fixed" v-if="headerNav" :style="'opacity:' + opacityStyle.opacity + ';'">
            <router-link to="/">
                <div class="iconfont iconfanhui return_icon"></div>
            </router-link>
            <div class="title">详情</div>
        </div>
    </div>
</template>

<script>
export default {
    name: "DetailHeader",
    data(){
        return{
            headerNav:false,
            opacityStyle:{
                opacity:0,
            }
        }
    },
    activated(){
        window.addEventListener('scroll',this.handleScroll);
    },
    deactivated(){
        window.removeEventListener('scroll',this.handleScroll);
    },
    methods:{
        handleScroll(){
            const top = document.documentElement.scrollTop;
            if(top > 37 && top < 230){
                this.opacityStyle.opacity = top / 230;
                this.headerNav = true;
            }else if(top >= 230){
                this.headerNav = true;
            }else{
                this.headerNav = false;
            }
        }
    }
}
</script>

<style scoped>
.header-abs {
    position: absolute;
    left: .2rem;
    top: .2rem;
    width: .8rem;
    height: .8rem;
    border-radius: .4rem;
    background-color: rgba(0, 0, 0, .8);

    display: flex;
    align-items: center;
    justify-content: center;
}

.header-left span {
    font-size: 0.5rem;
}

/* --------------------------------- */

.header-fixed {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    width: 100%;
    line-height: 0.86rem;
    background: #00bcd4;
    color: #ffffff;

    text-align: center;
}

.header-fixed .title {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);

    font-size: 0.4rem;
}

.header-fixed .return_icon {
    width: .64rem;
    text-align: center;
    font-size: 0.5rem;
}
</style>